﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace LunwenYun.Infrastructure.Entities.Repository
{
    [Table("T_IndustryCS")]
    public class T_IndustryCS : IEntity<T_IndustryCS>
    {
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        [Key]
        public string UserName { get; set; }

        /// <summary>
        /// 行业
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string Industry { get; set; }
        
        /// <summary>
        /// 承办机构
        /// </summary>
        public int Organization { get; set; }

        /// <summary>
        /// 客服类型（称谓）
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string Title { get; set; }

        [Column(TypeName = "nvarchar")]
        [StringLength(32)]
        public string QQ { get; set; }

        [Column(TypeName = "nvarchar")]
        [StringLength(32)]
        public string Phone { get; set; }

        [Column(TypeName="bit")]
        public bool Enable { get; set; }

        public DateTime CreateTime { get; set; }

        public override T_IndustryCS Find(string key)
        {
            return Find(c => c.UserName == key);
        }

        public override T_IndustryCS Find(System.Linq.Expressions.Expression<Func<T_IndustryCS, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.IndustryCS.FirstOrDefault(where);
                if (item != null)
                {
                    this.CreateTime = item.CreateTime;
                    this.Enable = item.Enable;
                    this.Industry = item.Industry;
                    this.Organization = item.Organization;
                    this.Phone = item.Phone;
                    this.QQ = item.QQ;
                    this.Title = item.Title;
                    this.UserName = item.UserName;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_IndustryCS, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.IndustryCS.Any(where);
            }
        }
    }
}
